package com.niit.project.service.impl;

import com.niit.project.dao.ReportDao;
import com.niit.project.dao.impl.ReportDaoImpl;
import com.niit.project.entity.Report;
import com.niit.project.service.ReportService;
import com.niit.project.utils.Dbutils;

import java.util.List;

public class ReportServiceImpl implements ReportService {
    private ReportDao  reportDao = new ReportDaoImpl();
    @Override
    public int addReport(String content) {
        int result = 0;
        try {
            Dbutils.begin();
            result = reportDao.insert(content);
            Dbutils.commit();
        } catch (Exception e) {
            Dbutils.rollback();
            throw new RuntimeException(e);
        }
        return result;
    }

    @Override
    public List<Report> showAllReport() {
        List<Report> report = null;
        try {
            Dbutils.begin();
            report = reportDao.select();
            Dbutils.commit();
        } catch (Exception e) {
            Dbutils.rollback();
            throw new RuntimeException(e);
        }
        return report;
    }
}
